
/**
 * Contains all operations for the object management page..
 */
var objectview = {
	FORM_URL: null,
	EDIT_OBJ: null,
	
	init: function() {
		this.FORM_URL = util.getURL('dbo_util_file')+'/object.jsp';
		this.EDIT_OBJ = dbobject();
		this.fetchList();
		layout.leftcolumn.setTitle('DBObject List');
		layout.mainpanel.setTitle('New DBObject');
	},
	
	loadForm: function() {
		req = new util.ajax.Request(this.FORM_URL);
		req.setResponseHandler('objectview.displayForm');
		req.loadFile();	
	},
	
	displayForm: function(reqst) {
		layout.mainpanel.setContent(reqst.response);
		layout.mainpanel.setTitle('New DBObject');
	},
	
	fetchList: function() {
		mydbolist = new dbobject();
		mydbolist.onReturn = 'objectview.listObjects';
		mydbolist.list({"status": 1, 'orderBy':'objectname'});
	},
	
	listObjects: function(dbolist) {
		lcc = layout.leftcolumn.getContent();
		lcc.innerHTML = "";
		this.listtable = document.createElement("table");
		this.listtable.width="100%";
		lcc.appendChild(this.listtable);

		rw = this.listtable.insertRow(-1);
		cl = rw.insertCell(-1);
		cl.style.border = '1px solid #cccccc';
		cl.innerHTML = '<a href="javascript:objectview.editObject(0)"><img src="images/new.png" border="0" width="10" height="10" align="absmiddle"/>&nbsp;<b>New DBObject</b></a>';	
		
		arr = dbolist.getArray();
		for (o=0;o<arr.length;o++) {
			rw = this.listtable.insertRow(-1);
			cl = rw.insertCell(-1);
			cl.width = "100%";
			cl.onmouseover = function() {
				this.style.backgroundColor="#eaeaea";
			}
			cl.onmouseout = function() {
				this.style.backgroundColor = "#ffffff";
			}
			cl.innerHTML = '<a href="javascript:objectview.editObject('+arr[o].getProperty('id')+')">'+arr[o].getProperty('objectname')+'</a>';	
		}		

		this.loadForm();
	},
	
	editObject: function(oid) {
		this.EDIT_OBJ = dbobject();
		if (oid > 0) { 
			this.EDIT_OBJ.onReturn = 'objectview.populateForm';
			this.EDIT_OBJ.load({"id": oid});
		} else {
			this.loadForm();
		}
	},
	
	populateForm: function(dbobj) {
		dbobj.toForm(document.forms['objectform']);
		layout.mainpanel.setTitle(dbobj.getProperty('jndiname')+' - '+dbobj.getProperty('objectname'));
	},
	
	saveObject: function() {
		frm = document.forms['objectform'];
		this.EDIT_OBJ.fromForm(frm);
		this.EDIT_OBJ.onReturn = "objectview.fetchList";
		this.EDIT_OBJ.save();
	},

	deleteObject: function() {
		frm = document.forms['objectform'];
		this.EDIT_OBJ.fromForm(frm);
		if (parseInt(this.EDIT_OBJ.getProperty('id')) == 0) {
			return;
		}
		this.EDIT_OBJ.onReturn = "objectview.fetchList";
		this.EDIT_OBJ.save({'status':99});
	}


}